package com.itheima.homework.blockQueue;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Cooker implements Runnable {
    private ArrayBlockingQueue<String> abq;

    public Cooker(ArrayBlockingQueue<String> abq) {
        this.abq = abq;
    }

    @Override
    public void run() {

        while (true) {
            Lock lock = new ReentrantLock();
            lock.lock();
            try {
                abq.put("汉堡包");
                System.out.println("厨师制作了一个汉堡包!");
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                lock.unlock();
            }
        }
    }
}
